#include "TPM_HAL_QE.h"
#include "SensorDataHandler.h"
#include "Services_QE.h"

#define MOTOR_TIMER                 1

#define MM_PRIMARY_PWM              0
#define MM_SECONDARY_PWM            2

#define MM_PRIM_PWM_DEFAULT         0
#define MM_SEC_PWM_DEFAULT          0

#define MM_PRIM_PWM_OFF             0
#define MM_SEC_PWM_OFF              0

#define MM_PRIM_PWM_MIN             15
#define MM_SEC_PWM_MIN              15 + MM_WINDOW

#define MOTOR_MAX_SPEED_INCREMENT   2
#define MOTOR_MIN_SPEED             20
#define MOTOR_SPEED_ZERO_LIMIT		17
#define MOTOR_MAX_SPEED             80

// This definition is critical, as any value lower than 600ns or higher
// than 900ns will result in damage to the hardware. With a counter rise 
// time of 20us each step equals to 250ns.
#define MM_WINDOW                   3

#define MOTOR_OVER_CURRENT          PTED_PTED5		// This pin used in final PCB
//#define MOTOR_OVER_CURRENT          PTDD_PTDD5	// This pin used in DEMOQE
#define MOTOR_SET                   PTED_PTED6
#define MOTOR_OVR_CURRENT_STATUS    PTED_PTED7

#define MOTOR_OVER_CURRENT_DD       PTEDD_PTEDD5	// This pin used in final PCB
//#define MOTOR_OVER_CURRENT_DD       PTDDD_PTDDD5	// This pin used in DEMOQE
#define MOTOR_SET_DD                PTEDD_PTEDD6
#define MOTOR_OVR_CURRENT_STATUS_DD PTEDD_PTEDD7

#define MOTOR_STATUS_OK             1
#define MOTOR_STATUS_OVERCURRENT    0

#define MOTOR_RECOVERED             0
#define MOTOR_SHORTED               1

#define MOTOR_ON    0xF0
#define MOTOR_OFF   0x0F
  
void vfnMotor_AdjustSpeed (void);

void vfnMotor_ConfigurePWM (void);

void vfnMotor_ConfigureGPIO (void);

void vfnMotor_TurnOn (void);